Welcome To
Strings
Methods


String Methods In Python

The python provides the multiple String methods to perform a text related works in the python code that is in the below.

Methods meaning Example Output
upper() The upper function is convert the all string characters into Upper case . text="Dashan"
print(text.upper())
DARSHAN
lower () The lower function is convert the all string characters into Lower case . text="DARSHAN"
print(text.upper())
darshan
swapcase() The swapcase function is convert the string individual characters are upper then that converts into lower case . if the string characters are lower case then converts that into lower case text="Darshan"
print(text.swapcase())
dARSHAN
islower() The islower() function is checks the give string is lower case or not . if the give string is lower case then the result will be true other wise false text="darshan"
print(text.islower())
True
isupper() The isupper() function is checks the give string is upper case or not . if the give string is upper case then the result will be true other wise false text="DARSHAN"
print(text.isupper())
True
isspace() The assigned variable is space are not if the variable has space then the value is true otherwise false text=" " print(text.isspace()) True
strip() The strip() function is remove the leading and trailing white spaces in the string text=" darshan "
print(text.strip())
darshan
lstrip() The lstrip() function is remove the leading white spaces in the string text=" darshan "
print(text.lstrip())
darshan
rstrip() The rstrip() function is remove the trailing white spaces in the string text=" darshan "
print(text.strip())
darshan
find(sub) The find( sub) function is used to search the sub string from the assigned string . it returns the index value text="darshan coder "
print(text.find("Coder"))
8
index(sub) The index( sub) function is used to search the sub string from the assigned string . and check the index value of the string . in the python code and it returns the index value text="darshan coder "
print(text.find("e"))
11
count(sub) the count(sub) function is used to find the number of non-overlapping occurrence of the substring sub . and the value is integer text="darshan coder "
print(text.count("d"))
2
len( String) the len() function is returns the length of the string . and returns the value as integer text="darshan coder "
print(len(text))
13
startswith( sub) the startswith(sub) function checks uf the string is starts with the specified prefix . return the result is boolean value either true or false text="darshan coder "
print(text.startswith("darshan"))
True
endswith(sub) the endswith(sub) function checks uf the string is ends with the specified postfix . return the result is boolean value either true or false text="darshan coder "
print(text.endswith("coder"))
True
isalpha() the isalpha() function is checks the given string is alphabetic like characters. if the given string characters are alphabetic then the result will be true otherwise False. the value is boolean value either true or False text="darshan coder "
print(text.isalpha())
True
isdigit() the isdigit() function is checks the given string is digit like characters. if the given string characters are digit then the result will be true otherwise False. the value is boolean value either true or False text="2345"
print(text.isdigit())
True
capitalize() the capitalize() function is used to convert the given string of first character is must be uppercase rest of the characters are lower case text="darshan"
print(text.capitalize())
Darshan
title() the title() function is used to convert the given string of every word first character is must be uppercase rest of the characters are lower case text="darshan is web developer"
print(text.title())
Darshan Is Web Developer
replace( old,new) the replace() function is used to replace the string with another string by using old string as new string ., when we replace the string by using the old string text="darshan is web developer"
print(text.replace("web","front end "))
Darshan Is front end Developer
split( old,new) the replace() function is used to replace the string with another string by using old string as new string ., when we replace the string by using the old string text="darshan is web developer"
print(text.replace("web","front end "))
Darshan Is front end Developer